package com.kexinde.wjifen.action;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.struts2.interceptor.RequestAware;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.kexinde.wjifen.model.ExchangeLog;
import com.kexinde.wjifen.model.Gift;
import com.kexinde.wjifen.model.NormalUser;
import com.kexinde.wjifen.model.Shop;
import com.kexinde.wjifen.service.IExchangeLogManager;
import com.opensymphony.xwork2.ActionSupport;
@Component("ExchangeLog")
@Scope("prototype")
public class ExchangeLogAction extends ActionSupport implements RequestAware {

	private ExchangeLog exchangeLog;
	private Gift gift;
	private Shop shop;
	private NormalUser normalUser;
	private IExchangeLogManager exchangeLogManager;
	private Map<String, Object> request;

	public String add() {
		if (this.exchangeLogManager.add(gift, shop, normalUser))
			return SUCCESS;
		else
			return ERROR;
	}

	public String showAllByShop() {
		List<ExchangeLog> exchangeLogs=this.exchangeLogManager.showAllByShop(shop.getId());
		request.put("exchangeLogs", exchangeLogs);
		return SUCCESS;
	}

	public String showAllByGift() {
		List<ExchangeLog> exchangeLogs=this.exchangeLogManager.showAllByGift(shop.getId(),gift.getId());
		request.put("exchangeLogs", exchangeLogs);
		return SUCCESS;
	}

	public String showAllByUser() {
		List<ExchangeLog> exchangeLogs = this.exchangeLogManager
				.showAllByUser(normalUser.getUserName());
		request.put("exchangeLogs", exchangeLogs);
		return SUCCESS;
	}

	@Override
	public void setRequest(Map<String, Object> request) {
		// TODO Auto-generated method stub
		this.request = request;
	}

	public ExchangeLog getExchangeLog() {
		return exchangeLog;
	}

	public void setExchangeLog(ExchangeLog exchangeLog) {
		this.exchangeLog = exchangeLog;
	}

	public IExchangeLogManager getExchangeLogManager() {
		return exchangeLogManager;
	}

	@Resource
	public void setExchangeLogManager(IExchangeLogManager exchangeLogManager) {
		this.exchangeLogManager = exchangeLogManager;
	}

	public Gift getGift() {
		return gift;
	}

	public void setGift(Gift gift) {
		this.gift = gift;
	}

	public Shop getShop() {
		return shop;
	}

	public void setShop(Shop shop) {
		this.shop = shop;
	}

	public NormalUser getNormalUser() {
		return normalUser;
	}

	public void setNormalUser(NormalUser normalUser) {
		this.normalUser = normalUser;
	}

}
